package com.emr.web.controller.emr;


import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.emr.common.annotation.Log;
import com.emr.common.enums.BusinessType;
import com.emr.module.domain.Bed;
import com.emr.module.domain.Deahtdis;
import com.emr.module.service.IDeahtdisService;
import com.emr.module.service.IPersonalService;
import com.emr.system.service.ISysUserService;
import com.emr.web.core.base.BaseController;
import com.emr.framework.web.page.TableDataInfo;
import com.emr.common.base.AjaxResult;

/**
 * 出院或死亡 信息操作处理
 * 
 * @author emr
 * @date 2019-02-21
 */
@Controller
@RequestMapping("/module/deahtdis")
public class DeahtdisController extends BaseController
{
    private String prefix = "module/deahtdis";
	
	@Autowired
	private IDeahtdisService deahtdisService;
	@Autowired
	private ISysUserService isysUserService;
	@Autowired
	private IPersonalService ipersonalService ;
	@RequiresPermissions("module:deahtdis:view")
	@GetMapping()
	public String deahtdis()
	{
	    return prefix + "/deahtdis";
	}
	
	/**
	 * 查询出院或死亡列表
	 */
	@RequiresPermissions("module:deahtdis:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Deahtdis deahtdis)
	{
		startPage();
		if("".equals(deahtdis.getPatientName())){
			deahtdis.setPatientName(null);
		}
        List<Deahtdis> list = deahtdisService.selectDeahtdisList(deahtdis);
		return getDataTable(list);
	}
	
	/**
	 * 新增出院或死亡
	 */
	@GetMapping("/add")
	public String add(ModelMap mmap)
	{
		mmap.put("posts",ipersonalService.selectOperationPersonal());
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存出院或死亡
	 */
	@RequiresPermissions("module:deahtdis:add")
	@Log(title = "出院或死亡", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Deahtdis deahtdis)
	{		
		return toAjax(deahtdisService.insertDeahtdis(deahtdis));
	}

	/**
	 * 修改出院或死亡
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		Deahtdis deahtdis = deahtdisService.selectDeahtdisById(id);
		mmap.put("posts", ipersonalService.selectUPersonalByIds(deahtdis.getBingrenId()));
		mmap.put("deahtdis", deahtdis);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存出院或死亡
	 */
	@RequiresPermissions("module:deahtdis:edit")
	@Log(title = "出院或死亡", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Deahtdis deahtdis)
	{		
		return toAjax(deahtdisService.updateDeahtdis(deahtdis));
	}
	
	/**
	 * 删除出院或死亡
	 */
	@RequiresPermissions("module:deahtdis:remove")
	@Log(title = "出院或死亡", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(deahtdisService.deleteDeahtdisByIds(ids));
	}
	
}
